using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Web.Mvc;
using InfoTech.Core.Service;
using InfoTech.LanTranh.MucVu.Bussiness;

namespace InfoTech.LanTranh.MucVu.Service
{
    public class LINHMUC_CHUCVUService : BaseService
    {
        public static bool Check_Insert_LINHMUC_CHUCVU(LINHMUC_CHUCVU linhmucChucVu)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &= dataContext.GetTable<LINHMUC_CHUCVU>().FirstOrDefault(c => c.TENCHUCVU.ToUpper() == linhmucChucVu.TENCHUCVU.ToUpper()) == null;
            return result;
        }

        public static bool Check_Update_LINHMUC_CHUCVU(LINHMUC_CHUCVU linhmucChucVu)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &= dataContext.GetTable<LINHMUC_CHUCVU>().FirstOrDefault(c => c.TENCHUCVU.ToUpper() == linhmucChucVu.TENCHUCVU.ToUpper() &&
                c.MACHUCVU != linhmucChucVu.MACHUCVU) == null;
            return result;
        }

        public static bool Check_Delete_LINHMUC_CHUCVU(string[] strings)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &= dataContext.GetTable<LINHMUC>().Where(c => strings.Contains(c.MACHUCVU + "")).FirstOrDefault() ==
                      null;
            result &= dataContext.GetTable<SOTANHIEN>().Where(c => strings.Contains(c.MACHUCVU + "")).FirstOrDefault() ==
                      null;
            return result;
        }

        public static void Delete(LINHMUC_CHUCVU linhmucChucvu)
        {
        }

        public static IEnumerable<SelectListItem> Get_List()
        {
            List<SelectListItem> list = new List<SelectListItem>();
            list.AddRange(InfoTech.Core.Data.Receiver.TypeObject<LINHMUC_CHUCVU>.SelectMany().OrderBy(c => c.PRIORITY).Select(
                    c => new SelectListItem() { Text = c.TENCHUCVU, Value = c.MACHUCVU + "" }));
            return list;
        }
    }
}
